package com.iwomy.secureplat.platform.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.iwomy.secureplat.app.api.entity.AppArticleCollectEntity;
import com.iwomy.secureplat.common.data.tenant.TenantContextHolder;
import com.iwomy.secureplat.platform.entity.DeviceEventReportEntity;
import com.iwomy.secureplat.platform.service.BasicDeviceService;
import com.iwomy.secureplat.platform.service.DeviceEventReportService;
import com.iwomy.secureplat.platform.service.QuartzService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * 报警事件类型
 *
 * @author pig
 * @date 2023-12-22 10:10:01
 */
@Service
public class QuartzServiceImpl implements QuartzService {

	@Resource
	private DeviceEventReportService deviceEventReportService;
	@Resource
	private BasicDeviceService basicDeviceService;

	@Override
	public void deviceEventReport() {
		TenantContextHolder.clear();
		//删除今天的所有数据再统计,用于页面刷新的时候
		LocalDate now = LocalDate.now();

		deviceEventReportService.remove(Wrappers.<DeviceEventReportEntity>lambdaQuery()
				.eq(DeviceEventReportEntity::getYear, now.getYear())
				.eq(DeviceEventReportEntity::getMonth, now.getMonth())
				.eq(DeviceEventReportEntity::getDay, now.getDayOfMonth()));


		List<DeviceEventReportEntity> deviceEventReportEntities = basicDeviceService.deviceEventReport();

		deviceEventReportService.saveBatch(deviceEventReportEntities);

	}
}